import Mock from 'mockjs'

export default {
  getMenu: config => {
    console.log(config);
    const { userName, password } = JSON.parse(config.body)
    console.log(JSON.parse(config.body))
    // 先判断用户是否存在
    // 判断账号和密码是否对应
    if (userName === 'admin' && password === 'admin') {
      return {
        code: 20000,
        data: {
          menu: [
            {
              path: '/user',
              name: 'user',
              redirect: "/user/info",
              meta: { title: "用户页面", icon: 'el-icon-user-solid' },
              children: [
                {
                  path: "/user/info",
                  name: "userinfo",
                  meta: { icon: 'el-icon-s-custom', title: "用户信息", url: "/user/info.vue" }
                },
                {
                  path: "/user/manager",
                  name: "manager",
                  meta: { icon: 'el-icon-s-grid', title: "用户管理", url: "/user/manager.vue" }
                },
              ]
            },
            {
              path: "/other",
              name: "other",
              redirect: '/other/page1',
              meta: { icon: "el-icon-location", title: "其他" },
              children: [
                {
                  path: '/other/page1',
                  name: 'page1',
                  meta: { icon: 'el-icon-s-claim', title: '页面1', url: "/other/page1.vue" },
                },
                {
                  path: '/other/page2',
                  name: 'page2',
                  meta: { icon: 'el-icon-setting', title: '页面2', url: "/other/page2.vue" }
                }
              ]
            }
          ],
          token: Mock.Random.guid(),
          role: "admin",
          message: '获取成功'
        }
      }
    } else if (userName === 'user' && password === 'user') {
      return {
        code: 20000,
        data: {
          menu: [
            {
              path: "/other",
              name: "other",
              redirect: '/other/page1',
              meta: { icon: "el-icon-location", title: "其他" },
              children: [
                {
                  path: '/other/page1',
                  name: 'page1',
                  meta: { icon: 'el-icon-s-claim', title: '页面1', url: "/other/page1.vue" },
                },
                {
                  path: '/other/page2',
                  name: 'page2',
                  meta: { icon: 'el-icon-setting', title: '页面2', url: "/other/page2.vue" }
                }
              ]
            }
          ],
          token: Mock.Random.guid(),
          role: "common",
          message: '获取成功'
        }
      }
    } else {
      return {
        code: -999,
        data: {
          message: '密码错误'
        }
      }
    }

  }
}
